package com.jcnet.bizaia.adapter;

import java.util.List;

import com.androidquery.AQuery;
import com.androidquery.callback.ImageOptions;
import com.jcnet.bizaia.App;
import com.jcnet.bizaia.R;
import com.jcnet.bizaia.bean.MainInfoBean;
import com.jcnet.bizaia.bean.VoiceInfoBean;
import com.squareup.picasso.Picasso;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class MainVoiceInfoAdapter extends BaseAdapter {

	private Context context;
	private List<VoiceInfoBean> infoBeans;
	public int count;

	public MainVoiceInfoAdapter(Context context, List<VoiceInfoBean> infoBeans) {
		super();
		this.context = context;
		this.infoBeans = infoBeans;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		count = infoBeans.size();
		return count;
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		ViewHolder holder;
		if(convertView == null)
		{
			holder = new ViewHolder();
			convertView = View.inflate(context,R.layout.voice_list_info, null);
			holder.imageView = (ImageView)convertView.findViewById(R.id.imageView) ;
			holder.titleTextView = (TextView)convertView.findViewById(R.id.title);
			holder.subTitleTextView = (TextView)convertView.findViewById(R.id.subTitle);
			holder.imgIconImageView = (ImageView)convertView.findViewById(R.id.icon);
			holder.timeTextView = (TextView)convertView.findViewById(R.id.titmeTitle);

			convertView.setTag(holder);
		}else
		{
			holder = (ViewHolder)convertView.getTag();

		}

		VoiceInfoBean infoBean  =   infoBeans.get(position);
		if(infoBean!=null){

			holder.titleTextView.setText(infoBean.getCname());
			holder.timeTextView .setText(infoBean.getDateline());
			holder.subTitleTextView.setText(infoBean.getContent());
			Picasso.with(context)
			.load(App.HTTP_PATH+infoBean.getAcsimages())
			.resize(80, 60)
			.centerCrop()
			.into(holder.imageView);
		}
		return convertView;
	}

	static class ViewHolder{
		ImageView imageView;
		TextView subTitleTextView;
		TextView titleTextView;
		ImageView imgIconImageView;
		TextView timeTextView;
	}
}
